<template>
  <div>
    <!-- 剽窃小马代码 -->
    <!-- 试卷名称 -->
    <h2 align="center">{{paper_info.name}}</h2>
    <!-- 试卷展示 -->
    <div style="padding: 10px 5%" class="box-card">
      <div v-for = "(questions,qType ,i) in allQuestionThisPaper" :key="i">
          <hr>
          <h4>{{questionType(qType)}}</h4> 
          <el-card  v-for="(q,j) in questions" :key="j" style="padding: 10px 20px">
              <el-divider><span style="color: rgb(239,160,48)">(分值：{{q.score}})</span></el-divider>
              <p class="title">第{{j+1}}题</p>
              <span class="title" v-html="q.name" style="margin: 20px"></span>
              <br>
              <br>
              <p>答案：</p>
              <span v-html="q.answer" style="margin: 20px"></span>
          </el-card >
      </div>
    </div>
    <!-- 按钮 -->
    <div style="text-align:center">
      <el-button type="success" icon="el-icon-check" size="mini" @click="paperIsPass(true)">通过</el-button>
      <el-button type="danger" icon="el-icon-circle-close" size="mini" @click="paperIsPass(flase)">不通过</el-button>
    </div>
  </div>
</template>

<script>
export default {
    name:'PaperDetail',
    data() {
      return {
        paper_info:{
          gmtCreate: '',
          gmtModified: '',
          id: '',
          name: '',
          permissionId: '',
          permissionName: '',
          remark: '',
          status: '',
          statusName: '',
          teachers:[],
        },
        //最原始的试卷纯数据
        allQuestionThisPaper:{},
        //试卷详情列表
        typeList:[],
      }
    },
    mounted() {
      this.paper_info = JSON.parse(this.$route.query.paper_info);
      this.getPageList();
    },
    methods: {
      //审核是否通过
      async paperIsPass(flag){
        let result = await this.$API.paper_updateState.passPaper(this.paper_info.id,flag);
        if(result.code==20000){
          if(flag){
            this.$message({
              type: 'success',
              message: '审核成功!'
            });
          }else{
            this.$message({
              type: 'warning',
              message: '已经不通过!'
            });
          }
          //跳转回试卷审核界面
          this.$router.push({
            name:'Paper_updateState',
          })
        }
      },
      // 返回题目的类型
      questionType(q){
          if(q=='1'){return "单选题"}
          else if(q == '2'){return "多选题"}
          else if(q == '3'){return "判断题"}
          else if(q == '4'){return "填空题"}
          else if(q == '5'){return "简答题"}
          else if(q == '6'){return "计算题"}
          else if(q == '7'){return "应用题"}
          else if(q == '8'){return "论述题"}
          else{return "其他题目"}
      },
      // 获取所有已知的题目类型
      async getTypeList() {
        //获取专业分类的请求，不需要携带参数
        let result = await this.$API.paper_updateState.reqGetTypeList();
        if(result.code==20000){
            this.typeList = result.data.typeList;
        }
      },
      // 获取试卷的所有信息
      async getPageList() {
        let result =
            await this.$API.paper_updateState.getPaperInventory(this.paper_info.id);
        if (result.code == 20000) {
            this.allQuestionThisPaper = result.data.question; //试卷所有题目信息
        }
      },
    },
}
</script>

<style scoped>
.title{
  font-size: 19px;
  font: bold;
}
</style>